package com.youka.bussiness.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.OrdersService;
import com.youka.bussiness.service.req.OrdersReqDto;
import com.youka.bussiness.service.req.OrdersUpdateDto;
import com.youka.bussiness.service.req.OrdersPageDto;
import com.youka.bussiness.service.res.OrdersDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;


import java.util.Map;

/**
 * 订单信息表 Controller
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Api(tags = "web-订单信息表")
@RestController()
@RequestMapping("/web/Orders")
public class OrdersController extends BaseController{

    @Autowired
    private OrdersService ordersService;

    /**
     * 查询订单信息表详情
     */
    @ApiOperation(value = "获取订单信息表详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = OrdersDto.class)
    })
    public RestResp findOrdersById(@RequestBody BaseEntity entity) {
        OrdersDto dto = ordersService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询订单信息表集合
     */
    @ApiOperation(value = "查询订单信息表集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = OrdersDto.class)
    })
    public RestResp listOrders(@RequestBody OrdersReqDto ordersPageDto) {
        List<OrdersDto> list = ordersService.selectByList(ordersPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询订单信息表分页
     */
    @ApiOperation(value = "查询订单信息表分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = OrdersDto.class)
    })
    public RestResp pageOrders(@RequestBody OrdersPageDto ordersPageDto) {
        IPage<OrdersDto> page = ordersService.selectByPage(ordersPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增订单信息表
     */
    @ApiOperation(value = "新增订单信息表")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = RestResp.class)
    })
    public RestResp addOrders(@RequestBody OrdersReqDto ordersReqDto) {
        ordersService.insert(ordersReqDto);
        return success();
    }

    /**
     * 编辑订单信息表
     */
    @ApiOperation(value = "编辑订单信息表")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = RestResp.class)
    })
    public RestResp updateOrders(@RequestBody OrdersUpdateDto ordersReqDto) {
        ordersService.update(ordersReqDto);
        return success();
    }

    /**
     * 删除订单信息表主键
     */
    @ApiOperation(value = "删除订单信息表")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询订单信息表详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        ordersService.deleteById(entity.getId());
        return success();
    }

}
